package com.muqi.app.user.widget;



import com.muqi.app.qlearn.student.R;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v4.app.FragmentActivity;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class RecordLevelEntry extends RelativeLayout implements android.content.DialogInterface.OnClickListener{
	private String[] items;
	private TextView mTitle;
	private TextView mlevelText;
	private AlertDialog  levelDailog;
	private FragmentActivity mActivity;
	
	private int selectedPosition=0;
	
	public RecordLevelEntry(FragmentActivity mActivity, String title,String[] items) {
		super(mActivity);
		this.mActivity = mActivity;
		this.items=items;
		init(mActivity);
		initDialog();
		mTitle.setText(title);
	}
     /**
      *  初始化选择器
      */
	private void initDialog() {
		AlertDialog.Builder builder=new Builder(mActivity);
		levelDailog =	builder.setTitle("选择等级")
		.setSingleChoiceItems(items, 0, this)
		.setPositiveButton("确定",this)
		.setCancelable(true).create();
		
	}

	public RecordLevelEntry(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
	}

	public RecordLevelEntry(Context context, AttributeSet attrs, int defStyleAttr) {
		super(context, attrs, defStyleAttr);
		init(context);
	}

	private void init(Context context) {
		LayoutInflater inflater = LayoutInflater.from(context);
		View view = inflater.inflate(R.layout.record_date_selecter_entry, this);
		mTitle = (TextView) view.findViewById(R.id.title);
		mlevelText = (TextView) view.findViewById(R.id.recordDatetext);
		mlevelText.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(mActivity!=null){
				  levelDailog.show();
				}
			}
		});
	}

	
	public void setEditSize(float size) {
		mlevelText.setTextSize(size);
	}

	public void setEditColor(int resId) {
		mlevelText.setTextColor(resId);
	}
	
	/**
	 * 
	 */
	public String getDateTextValue() {
		return mlevelText.getText().toString().trim();
	}
    /**
     * 
     * @return 获取对应的可以值
     */
	public String getTextViewValue(){
		return mTitle.getText().toString().trim();
	}
	

	@Override
	public void onClick(DialogInterface dialog, int which) {
		// TODO Auto-generated method stub
		if(which==-1){ // 表示选择的是确定按钮
		
		  mlevelText.setText(items[selectedPosition]);
		
		}else{ // 点击item
			selectedPosition=which;
		}
		
	}
}
